#include <vector>
#include "behaviors_recorder.hpp"
#include "exact_argument_matcher.hpp"
#include "invocation_matcher.hpp"
#include "return_value_behavior.hpp"
#include "throw_exception_behavior.hpp"

using std::vector;

namespace vimock {
behaviors_recorder::behaviors_recorder() : 
	behaviors(new vector<behavior>()) {
}
void behaviors_recorder::record_invocation(invocation inv) {
	object obj(inv->get_object());
	object func(inv->get_function());
	argument_matcher_vector argument_matchers(new vector<argument_matcher>());
	object_vector arguments(inv->get_arguments());
	vector<object>::iterator arg_iter = arguments->begin();
	vector<object>::iterator end_arg_iter = arguments->end();
	for (;arg_iter != end_arg_iter; ++arg_iter) {
		object arg(*arg_iter);
		argument_matcher arg_matcher(new exact_argument_matcher(arg));
		argument_matchers->push_back(arg_matcher);
	}
	last_inv_matcher = invocation_matcher(new _invocation_matcher(obj, func, argument_matchers));
}
void behaviors_recorder::record_value_to_return(object value_to_return) {
	behavior bhv(new return_value_behavior(last_inv_matcher, value_to_return));
	behaviors->push_back(bhv);
}
void behaviors_recorder::record_exception_to_throw(exception_thrower ex_to_throw) {
	behavior bhv(new throw_exception_behavior(last_inv_matcher, ex_to_throw));
	behaviors->push_back(bhv);
}
behavior_vector behaviors_recorder::get_behaviors() {
	return behaviors;
}
}
